//
//  XFXDidVoiceViewController.m
//  XFXnews
//
//  Created by dllo on 16/1/29.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "XFXDidVoiceViewController.h"
#import "XFXDidVoiceModel.h"
#import "XFXDidVoiceTableViewCell.h"
#import <AVFoundation/AVFoundation.h>
#import "XFXPlayerView.h"

@interface XFXDidVoiceViewController ()
<
    XFXPlayerViewDelegate,
    UITableViewDataSource,
    UITableViewDelegate
>


@property (nonatomic, strong)NSMutableArray *allArray;
@property (nonatomic, strong)UITableView *myTableView;
@property (nonatomic, strong)XFXPlayerView *myView;




@end

@implementation XFXDidVoiceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    self.navigationController.navigationBarHidden = YES;
    // 隐藏导航栏
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    
    self.allArray = [NSMutableArray array];
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 300*XFXHEIGHT/736, XFXWIDTH, XFXHEIGHT-300*XFXHEIGHT/736) style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;

    self.isUpLoading = NO;
    [self getJson];
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_myTableView reloadData];
    [self.view addSubview:self.myTableView];
    

    
    UINib *nib = [UINib nibWithNibName:@"XFXDidVoiceTableViewCell" bundle:[NSBundle mainBundle]];
    [self.myTableView registerNib:nib forCellReuseIdentifier:@"cell"];

    self.myView = [[XFXPlayerView alloc]initWithFrame:CGRectMake(0, 0, XFXHEIGHT, 300*XFXHEIGHT/736)];
    self.myView.model = self.model;
    self.myView.delegate = self;
    [self.view addSubview:self.myView];
    
    
}
- (void)getJson{

    NSString *str = [NSString stringWithFormat:@"http:comment.api.163.com/api/json/post/list/new/normal/video_bbs/%@/desc/0/10/10/2/2", self.model.replyid];
    
    [XFXAppTools getNewsWithHeadline:str block:^(id reulst) {
        NSMutableArray *array = [reulst objectForKey:@"newPosts"];
        for (NSDictionary *dic in array) {
            NSMutableDictionary *dic1 = [dic objectForKey:@"1"];
            XFXDidVoiceModel *model = [[XFXDidVoiceModel alloc] init];
            [model setValuesForKeysWithDictionary:dic1];
            [self.allArray addObject:model];
        }

        [_myTableView reloadData];
     
    } error:^(NSError *error) {
        
    
    }];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.allArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    XFXDidVoiceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.model = self.allArray[indexPath.row];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100*XFXHEIGHT/736;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

 
- (void)back{
    [self.myView.player pause];
    self.navigationController.navigationBarHidden = NO;
    [self.navigationController popToRootViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
